import Vue from 'vue'
import Vuex from 'vuex'
import { getToken,setToken,removeToken,setnanxunId,setnanxunRoleId,setnanxunSquardonId } from '@/utils/auth'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: getToken(),
    roleId: '',
    squadron: "",
    userId: ""
  },
  getters: {},
  mutations: {
    storeToken(state, payload) {
      state.token = payload.token
      state.roleId = payload.role
      state.squadron = payload.squadron
      state.userId = payload.userId
      setToken(payload.token)
      setnanxunId(payload.userId)
      setnanxunRoleId(payload.role)
      setnanxunSquardonId(payload.squadron)
      // localStorage.setItem('nanxun_token', payload.token)
      // localStorage.setItem('nanxun_roleId', payload.role)
      // localStorage.setItem('nanxun_squadron', payload.squadron)
      // localStorage.setItem('nanxun_id', payload.userId)
    },
    delToken() {
      removeToken()
    }
  },
  actions: {},
  modules: {}
})
